<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Sharing (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Sharing (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Sharing (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="RTL.html" rel="up" title="RTL">
<link href="Reading-RTL.html" rel="next" title="Reading RTL">
<link href="Changing-Multiple-RTL-SSA-Instructions.html" rel="prev" title="Changing Multiple RTL SSA Instructions">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en">
<span id="Sharing"></span><div class="header">
<p>
Next: <a href="Reading-RTL.html" accesskey="n" rel="next">Reading RTL</a>, Previous: <a href="RTL-SSA.html" accesskey="p" rel="prev">RTL SSA</a>, Up: <a href="RTL.html" accesskey="u" rel="up">RTL</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Structure-Sharing-Assumptions"></span><h3 class="section">14.22 Structure Sharing Assumptions</h3>
<span id="index-sharing-of-RTL-components"></span>
<span id="index-RTL-structure-sharing-assumptions"></span>

<p>The compiler assumes that certain kinds of RTL expressions are unique;
there do not exist two distinct objects representing the same value.
In other cases, it makes an opposite assumption: that no RTL expression
object of a certain kind appears in more than one place in the
containing structure.
</p>
<p>These assumptions refer to a single function; except for the RTL
objects that describe global variables and external functions,
and a few standard objects such as small integer constants,
no RTL objects are common to two functions.
</p>
<ul>
<li> <span id="index-reg_002c-RTL-sharing"></span>
Each pseudo-register has only a single <code>reg</code> object to represent it,
and therefore only a single machine mode.

</li><li> <span id="index-symbolic-label"></span>
<span id="index-symbol_005fref_002c-RTL-sharing"></span>
For any symbolic label, there is only one <code>symbol_ref</code> object
referring to it.

</li><li> <span id="index-const_005fint_002c-RTL-sharing"></span>
All <code>const_int</code> expressions with equal values are shared.

</li><li> <span id="index-const_005fpoly_005fint_002c-RTL-sharing"></span>
All <code>const_poly_int</code> expressions with equal modes and values
are shared.

</li><li> <span id="index-pc_002c-RTL-sharing"></span>
There is only one <code>pc</code> expression.

</li><li> <span id="index-const_005fdouble_002c-RTL-sharing"></span>
There is only one <code>const_double</code> expression with value 0 for
each floating point mode.  Likewise for values 1 and 2.

</li><li> <span id="index-const_005fvector_002c-RTL-sharing"></span>
There is only one <code>const_vector</code> expression with value 0 for
each vector mode, be it an integer or a double constant vector.

</li><li> <span id="index-label_005fref_002c-RTL-sharing"></span>
<span id="index-scratch_002c-RTL-sharing"></span>
No <code>label_ref</code> or <code>scratch</code> appears in more than one place in
the RTL structure; in other words, it is safe to do a tree-walk of all
the insns in the function and assume that each time a <code>label_ref</code>
or <code>scratch</code> is seen it is distinct from all others that are seen.

</li><li> <span id="index-mem_002c-RTL-sharing"></span>
Only one <code>mem</code> object is normally created for each static
variable or stack slot, so these objects are frequently shared in all
the places they appear.  However, separate but equal objects for these
variables are occasionally made.

</li><li> <span id="index-asm_005foperands_002c-RTL-sharing"></span>
When a single <code>asm</code> statement has multiple output operands, a
distinct <code>asm_operands</code> expression is made for each output operand.
However, these all share the vector which contains the sequence of input
operands.  This sharing is used later on to test whether two
<code>asm_operands</code> expressions come from the same statement, so all
optimizations must carefully preserve the sharing if they copy the
vector at all.

</li><li> No RTL object appears in more than one place in the RTL structure
except as described above.  Many passes of the compiler rely on this
by assuming that they can modify RTL objects in place without unwanted
side-effects on other insns.

</li><li> <span id="index-unshare_005fall_005frtl"></span>
During initial RTL generation, shared structure is freely introduced.
After all the RTL for a function has been generated, all shared
structure is copied by <code>unshare_all_rtl</code> in <samp>emit-rtl.cc</samp>,
after which the above rules are guaranteed to be followed.

</li><li> <span id="index-copy_005frtx_005fif_005fshared"></span>
During the combiner pass, shared structure within an insn can exist
temporarily.  However, the shared structure is copied before the
combiner is finished with the insn.  This is done by calling
<code>copy_rtx_if_shared</code>, which is a subroutine of
<code>unshare_all_rtl</code>.
</li></ul>

<hr>
<div class="header">
<p>
Next: <a href="Reading-RTL.html" accesskey="n" rel="next">Reading RTL</a>, Previous: <a href="RTL-SSA.html" accesskey="p" rel="prev">RTL SSA</a>, Up: <a href="RTL.html" accesskey="u" rel="up">RTL</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
